<?php
namespace app\message\validate;

use think\Validate;

/**
 * Created by PhpStorm.
 * User: wanghaibo
 * Date: 18/1/31
 * Time: 17:56
 */
class MessageValidate extends Validate
{
    protected $rule = [
        'truename|姓名'  =>  'require|max:55|token',
        'tel|手机/固话'   =>      'require|checkTel',
        'qq|QQ'    =>  'number',
        'content|要求'   =>  'require|max:255'
        ];
    protected $message = [
        'truename.length'   =>  '姓名长度过长'
    ];
    // 自定义验证规则
    protected function checkTel($value)
    {
        $isMob="/^1[3-8]{1}[0-9]{9}$/";
        $isTel="/^([0-9]{3,4}-)?[0-9]{7,8}$/";
        if(!preg_match($isMob,$value) && !preg_match($isTel,$value)){
            return '手机/固话格式不正确';
        }
        return true;
    }
}